<div class="box box-info">
  <div class="box-header with-border">
    <h3 class="box-title">修改系统菜单表信息</h3>
    <div class="box-tools">
		<span onclick="HtmlRender('${BASE}/admin/sys/SysMenu/index')" class="btn btn-info btn-sm">系统菜单表列表</span>
		<span onclick="HtmlRender('${BASE}/admin/sys/SysMenu/add')" class="btn btn-info btn-sm">添加系统菜单表</span>
    </div>
  </div>
  <form action="${BASE}/admin/sys/SysMenu/save" id="form_save" method="post" class="form form-horizontal">
    <input type="hidden" id="obj_id" name="id" value="${obj.id}">
      <input type="hidden" id="parentId" name="parentId" value="${obj.parentId}" />
      <input type="hidden" id="level" name="level" value="${obj.level}" />
    <div class="box-body">
      
      <div class="form-group">
        <label for="parentId" class="col-sm-3 control-label">上级菜单：</label>
        <div class="col-sm-6">
        <div class="input-group">
          <input type="text" id="parentName" name="parentName" value="${obj.parentName}" class="form-control" readonly="readonly" >
          <span class="input-group-btn" id="btn_span_parentIds"><button type="button" class="btn btn-info btn-flat"><i class="fa fa-th"></i> 选择上级菜单</button></span>
        </div>
        </div>
        <div class="col-sm-3"> </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label">菜单名称：</label>
        <div class="col-sm-6">
          <input type="text" id="name" name="name" value="${obj.name}" class="form-control">
        </div>
        <div class="col-sm-3"> </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label">链接：</label>
        <div class="col-sm-6">
          <input type="text" id="href" name="href" value="${obj.href}" class="form-control">
        </div>
        <div class="col-sm-3"> </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label">图标：</label>
        <div class="col-sm-6">
        <div class="input-group">
          <span class="input-group-addon"><i class='<% if(isEmpty(obj.icon)){print("fa fa-circle-o");}else{print(obj.icon);} %>' ></i></span>
          <input type="text" id="icon" name="icon" value='<% isEmpty(obj.icon)?print("fa fa-circle-o"):print(obj.icon); %>' class="form-control">
          <span class="input-group-btn" id="btn_span_icon"><button type="button" class="btn btn-info btn-flat"><i class="fa fa-th"></i> 选择图标</button></span>
        </div>
        </div>
        <div class="col-sm-3"> </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label">是否在菜单中显示：</label>
        <div class="col-sm-6">
          <label class="control-label"><input type="radio" name="isShow" class="minimal" value="1" ${obj.isShow==1?"checked"}> 显示</label>
          <label class="control-label"><input type="radio" name="isShow" class="minimal" value="0" ${obj.isShow==0?"checked"}> 隐藏</label>
        </div>
        <div class="col-sm-3"> </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label">权限标识：</label>
        <div class="col-sm-6">
          <input type="text" id="permission" name="permission" value="${obj.permission}" class="form-control">
        </div>
        <div class="col-sm-3"> </div>
      </div>
	
      <div class="form-group">
        <label class="col-sm-3 control-label">备注信息：</label>
        <div class="col-sm-6">
          <textarea id="remarks" name="remarks" cols="" rows="" class="form-control"  placeholder="备注信息...255个字符以内" dragonfly="true" onKeyUp="textarealength(this,255)">${obj.remarks}</textarea>
          <p class="textarea-numberbar"><em class="textarea-length">0</em>/255</p>
        </div>
        <div class="col-sm-3"> </div>
      </div>
      
    </div>
      <div class="box-footer">
        <div class="col-sm-10 col-sm-offset-2">
          <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
        </div>
      </div>
    
    <div class="col-xs-1">&nbsp;</div>
  </form>

  <div id="div_menu_select_tree" class="content" style="display: none;">
    <div class="box" style="height: 350px">
      <div class="box-body">
        <ul id="ul_menu_select_tree" class="ztree"></ul>
      </div>
    </div>
  </div>
  
</div>
<script type="text/javascript">
$(function(){
	
    $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
        checkboxClass: 'icheckbox_minimal-blue',
        radioClass: 'iradio_minimal-blue'
      });
      
  	var menuTree;
  	var tree_setting = {};
  	
  	function showDailog(){
  		if(!menuTree){
  			$("#ul_menu_select_tree").html("<li>没有菜单数据</li>");
  		}
  		layer.open({
  			type: 1,
  			shadeClose:true,
  			title :'选择上级菜单',
  			area: ['500px', '500px'],
  			content: $('#div_menu_select_tree'),
  			btn: ['确认选择', '取消', '设置为顶级菜单'],
  			btn1: function(index, layero){
  				if(menuTree){
  					var nodes = menuTree.getSelectedNodes()[0];
  					if(nodes){
  						$("#form_save #parentId").val(nodes.id);
  						$("#form_save #level").val(parseInt(nodes.level)+1);
  						$("#form_save #parentName").val(nodes.name);
  					}
  				};
  				layer.close(index);
  			},
  			btn2: function(index, layero){}, 
  			btn3: function(index){
  				$("#form_save #parentId").val(0);
  				$("#form_save #level").val(0);
  				$("#form_save #parentName").val('顶级菜单');
  			}
  		});
  	}
  	function select_parent_menu(){
  		if(menuTree){
  			showDailog();
  		}else{
  			$.getJSON("${BASE}/admin/sys/SysMenu/selectTree",{}, function(str){
  				$("#ul_menu_select_tree").text("");
  				if(str)
  					menuTree = $.fn.zTree.init($("#ul_menu_select_tree"), tree_setting, str);
  				else
  					menuTree = null;
  				showDailog();
  			});
  		}
  	}
  	
  	$("#form_save #parentName, #form_save #btn_span_parentIds").click(select_parent_menu);
  	
	$("#form_save").validate({
		errorPlacement: function(error, element) {
			error.appendTo(element.parent());
		},
		submitHandler : function(form) {
			layer.load(1, {shade: [0.3,'#fff']});
			$(form).ajaxSubmit({
				dataType:"json",
				success:function( jsondata ){
					layer.closeAll('loading');
					if( jsondata.code == "001" ){
						layer.msg(jsondata.msg, {icon: 6,offset: '45px'});
						HtmlRender("${BASE}/admin/sys/SysMenu/index");
					}else{
						layer.msg(jsondata.msg, {icon: 5,offset: '45px'});
					}
				}
			});
		},
		rules : {
			name : {
				required : true
			}
		}, 
		messages : { 
			name : { 
				required : "名称不能为空"
			}
		}
	});
});
</script>